package cn.itcast.mapper;

import cn.itcast.dto.DishDto;
import cn.itcast.entity.Dish;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface IDishMapper {
    @Select("SELECT COUNT(*) FROM dish WHERE category_id =#{id}")
    int findCount(Long id);


    @Insert("insert into dish values(null,#{name},#{categoryId},#{price},#{code},#{image},#{description}" +
            ",#{status},0,#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void save(DishDto dishDto);

    //展示列表
    List<DishDto> findByName(String name);
    //根据id查询
  @Select("select * from dish where id=#{id}")
    Dish findById(Long id);
    @Update("update dish set `name`=#{name},category_id=#{categoryId},price=#{price},code=#{code}" +
            ",description=#{description},status=#{status},update_time=#{updateTime},update_user=#{updateUser} where " +
            "id=#{id}")
    void update(DishDto dishDto);


    /**
     * 根据categoryId查询所有dish
     */

    @Select("select * from dish where category_id =#{categoryId}")
    List<Dish> list(Long categoryId);

    /**
     * 根据categoryId或者DishId和status为1查询菜品
     * @param categoryId
     * @param status
     * @return
     */
    List<DishDto> findByCategoryIdAndStatus( Long categoryId,  Integer status);
}
